package com.credithc.signature.manager.controller.management;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.baseserv.pageHelper.PageInfo;
import com.credithc.signature.manager.ro.TemplateRo;
import com.credithc.signature.manager.service.TemplateMService;
import com.credithc.signature.manager.vo.TemplateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/manager/scs/v2/management")
public class TemplateMController {

    @Autowired
    private MessageFactory messageFactory;

    @Autowired
    private TemplateMService templateService;

    @GetMapping("/template")
    public Message search(TemplateRo templateRo){

        PageInfo<TemplateVo> pageInfo = templateService.search(templateRo);
        Map map = new HashMap<>(16);
        map.put("pageInfo", pageInfo);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS,map);
    }

    @GetMapping("/template/history")
    public Message searchHistory(TemplateRo templateRo){

        PageInfo<TemplateVo> pageInfo = templateService.searchHistory(templateRo);
        Map map = new HashMap<>(16);
        map.put("pageInfo", pageInfo);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS,map);
    }

    @GetMapping("/template/status/{id}/{status}")
    public Message status(@PathVariable(name = "id", required = true) Long id, @PathVariable(name = "status", required = true) Integer status){

        templateService.updateStatus(id,status);

        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }

    @GetMapping("/template/vip/{id}/{vip}")
    public Message vip(@PathVariable(name = "id", required = true) Long id, @PathVariable(name = "vip", required = true) Integer vip){

        templateService.updateVip(id,vip);

        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }


    @GetMapping("/template/count")
    public Message count(){
        Integer count = templateService.getCount();
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS,count);
    }

    @GetMapping("/template/history/count")
    public Message historyCount(){
        Integer count = templateService.getHistoryCount();
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS,count);
    }

}
